﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YJKTextTool
{
	public partial class SpecialCharacterForm : System.Windows.Forms.Form
	{
		public SpecialCharacterForm(string typeName)
		{
			this.InitializeComponent();
			YJKProcessTools hyprocessTools = new YJKProcessTools();
			hyprocessTools.ShowInTaskbarChange(this);
			base.SetStyle(ControlStyles.UserPaint, true);
			base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			base.SetStyle(ControlStyles.DoubleBuffer, true);
			this.m_specialCharacters = Common.GetSpecialCharacters();
			List<string> dataSource = this.m_specialCharacters.Keys.ToList<string>();
			this.cmbTypes.DataSource = dataSource;
			if (string.Empty != typeName)
			{
				this.cmbTypes.Text = typeName;
			}
		}

		private void SpecialCharacterForm_Paint(object sender, PaintEventArgs e)
		{
			Graphics graphics = e.Graphics;
			Pen pen = new Pen(Color.Black, 1f);
			for (int i = 0; i < 7; i++)
			{
				Point pt = new System.Drawing.Point(20, 40 + 30 * i);
				Point pt2 = new System.Drawing.Point(320, 40 + 30 * i);
				graphics.DrawLine(pen, pt, pt2);
			}
			for (int j = 0; j < 11; j++)
			{
				Point pt3 = new System.Drawing.Point(20 + 30 * j, 40);
				Point pt4 = new System.Drawing.Point(20 + 30 * j, 220);
				graphics.DrawLine(pen, pt3, pt4);
			}
			string text = this.cmbTypes.Text;
			List<string> list = this.m_specialCharacters[text];
			for (int k = 0; k < list.Count; k++)
			{
				string s = list[k];
				Font font = new Font("微软雅黑", 18f);
				int num = k / 10;
				int num2 = k % 10;
				RectangleF layoutRectangle = new RectangleF(new PointF((float)(20 + 30 * num2), (float)(40 + 30 * num)), new SizeF(30f, 30f));
				graphics.DrawString(s, font, Brushes.Black, layoutRectangle);
			}
			if (this.m_mouseClick)
			{
				pen = new Pen(Color.Red, 2f);
				graphics.DrawRectangle(pen, new Rectangle(this.m_ptSelectCell, new Size(30, 30)));
			}
		}

		private void cmbTypes_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.m_mouseClick = false;
			base.Invalidate();
		}

		private void SpecialCharacterForm_MouseClick(object sender, MouseEventArgs e)
		{
			Point location = e.Location;
			if (location.X > 20 && location.X < 320 && location.Y > 40 && location.Y < 220)
			{
				int num = (location.X - 20) / 30;
				int num2 = (location.Y - 40) / 30;
				this.m_ptSelectCell = new System.Drawing.Point(20 + 30 * num, 40 + 30 * num2);
				string text = this.cmbTypes.Text;
				List<string> list = this.m_specialCharacters[text];
				if (num2 * 10 + num < list.Count)
				{
					this.m_selCharater = list[num2 * 10 + num];
				}
				else
				{
					this.m_selCharater = string.Empty;
				}
				this.m_selType = this.cmbTypes.Text;
				this.m_mouseClick = true;
				base.Invalidate();
			}
		}

		private void SpecialCharacterForm_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if (this.m_mouseClick)
			{
				base.DialogResult = DialogResult.OK;
				base.Close();
			}
		}

		private void SpecialCharacterForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void SpecialCharacterForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
		}

		private const int OriginX = 20;

		private const int OriginY = 40;

		private const int CellSize = 30;

		private Point m_ptSelectCell = Point.Empty;

		private bool m_mouseClick;

		public string m_selType = string.Empty;

		public string m_selCharater = string.Empty;

		private Dictionary<string, List<string>> m_specialCharacters;
	}
}
